package com.congee02.aop.proxy.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @author congee(congee02 @ 163.com)
 * @date 1/26/2023 12:24 PM
 */
public class FlexibleDynamicProxyFactory implements DynamicProxyFactory {

    private final Object target;
    private final InvocationHandler handler;

    public FlexibleDynamicProxyFactory(Object target, InvocationHandler handler) {
        this.target = target;
        this.handler = handler;
    }

    @Override
    public Object getProxyInstance() {
        Class<?> clazz = target.getClass();
        return
                Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), handler);
    }
}
